//
//  MainViewController.m
//  SinaWeiBo
//
//  Created by 黎跃春 on 15/10/19.
//  Copyright (c) 2015年 黎跃春. All rights reserved.
//

#import "MainViewController.h"
#import "FansListViewController.h"
#import "AttensionListViewController.h"
#import "MineWeiBoViewController.h"
#import "HomePageViewController.h"
#import "MineViewController.h"
#import "RDVTabBarItem.h"


@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setUpViewControllers];
    
}

- (void)setUpViewControllers {

//    1.主页
    HomePageViewController *homePageVC = [[HomePageViewController alloc] initWithNibName:@"HomePageViewController" bundle:nil];
    SCNavigationController *homePageNav = [[SCNavigationController alloc] initWithRootViewController:homePageVC];
    
    
    
    
    
//    2.粉丝列表
    FansListViewController *fansListVC = [[FansListViewController alloc] initWithNibName:@"FansListViewController" bundle:nil];
    SCNavigationController *fansListNav = [[SCNavigationController alloc] initWithRootViewController:fansListVC];
    
//    3.我的微博
    MineWeiBoViewController *mineWeiboVC = [[MineWeiBoViewController alloc] initWithNibName:@"MineWeiBoViewController" bundle:nil];
    SCNavigationController *mineWeiboNav = [[SCNavigationController alloc] initWithRootViewController:mineWeiboVC];
    
//    4.关注列表
    AttensionListViewController *attensionListVC = [[AttensionListViewController alloc] initWithNibName:@"AttensionListViewController" bundle:nil];
    SCNavigationController *attensionListNav = [[SCNavigationController alloc] initWithRootViewController:attensionListVC];
    
//    5.我的
    MineViewController *mineVC = [[MineViewController alloc] initWithNibName:@"MineViewController" bundle:nil];
    SCNavigationController *mineNav = [[SCNavigationController alloc] initWithRootViewController:mineVC];
    
    
//    6.将以上五个导航控制器装到数组中作为tabBarController的viewControllers属性
    
    self.viewControllers = @[homePageNav, fansListNav, mineWeiboNav, attensionListNav, mineNav];
    
    [self customizeTabBarForController:self];
    
}

- (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {
    
    NSArray *tabBarItemTitles = @[@"主页", @"粉丝列表", @"我的微博", @"关注列表", @"我的"];
    NSArray *tabBarItemImages = @[@"shouye", @"shouye", @"shouye", @"shouye", @"shouye"];
    
    NSInteger index = 0;
    
    
    NSDictionary *textAttributes_normal = nil;
    NSDictionary *textAttributes_selected = nil;
    
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
        textAttributes_normal = @{
                                  NSFontAttributeName: [UIFont systemFontOfSize:12],
                                  NSForegroundColorAttributeName: [UIColor colorWithRed:147/255.0 green:145/255.0 blue:145/255.0 alpha:1.0],
                                  };
        textAttributes_selected = @{
                                    NSFontAttributeName: [UIFont systemFontOfSize:12],
                                    NSForegroundColorAttributeName: [UIColor colorWithRed:199/255.0 green:57/255.0 blue:32/255.0 alpha:1.0],
                                    };
    }
    
    
    for (RDVTabBarItem *item in [[tabBarController tabBar] items]) {
        
//        配置title颜色和图标颜色一致
        item.unselectedTitleAttributes = textAttributes_normal;
        item.selectedTitleAttributes = textAttributes_selected;
        
        
        
//         设置title
        item.title = tabBarItemTitles[index];
        NSString *normalImageName = [NSString stringWithFormat:@"%@_normal.png",tabBarItemImages[index]];
        UIImage *normalImage = [UIImage imageNamed:normalImageName];
        
        NSString *selectedImageName = [NSString stringWithFormat:@"%@_selected.png",tabBarItemImages[index]];
        UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
        
        [item setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:normalImage];
        
        
        index++;
    }
}





@end










